home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: changing the size linked to a pointer with keeping the same address
- Date: Fri, 05 Jan 1996 17:38:09 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4cjnlc$s0a@news.halcyon.com>
- References: <4chia6$1sl@vishnu.jussieu.fr>
- NNTP-Posting-Host: blv-pm3-ip9.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- ricou@ann.jussieu.fr (Olivier Ricou) wrote:
-
- >Hi,
-
- > I want to do a Resize function for my Vector class{int dim, TYPE* elts}.
- >My problem is I can have pointers to elts, so I cannot delete elts and
- >make a new one (this would give me an address which has very few chances
- >to be the same one than before) or all the pointers to (old) elts will
- >point to nothing.
-
- > So I would like to have a way to change the size linked to a pointer
- >whitout changing the address of the pointer.
-
- > yours,
-
- > Olivier.
-
- >--
- >Olivier Ricou
- >Lab. Analyse Numerique, Paris VI ricou@ann.jussieu.fr
- >tel (1) 44 27 71 70 / 44 07 http://www.ann.jussieu.fr/
-
-
- As a rule, I think you're out of luck with the dynamic array appraoch
- to the vector. The realloc() function is guaranteed to keep the same
- address if the size of the array shrinks, but not guaranteed to keep
- the address if the array grows. In all cases, realloc() preserves the
- contents of the array, even if it has to move it.
-
- Of course, if your vector were implemented as an array of pointers, or
- a linked-list, then, obviously, no problem. Each element will always
- point where it initially pointed, but the elements needn't occupy
- contiguous memory.
-
- Alternatively, ensure no one aliases that memory.
-
- Lastly, under NT, you can reserve virtual memory address space w/o
- actually allocating it all. You can then commit the memory in parcels
- as large or small as you like, and the memory will *appear* to your
- program as if it were contiguous. (You can reserve and commit more
- than the amount of available RAM this way, too; it appends a range of
- the page file to the mapping to make up for the shortage).
-
- Does this help?
- --Norm
-
-